package com.xxxx.yeb.controller;

import com.xxxx.yeb.pojo.Admin;
import com.xxxx.yeb.pojo.Menu;
import com.xxxx.yeb.pojo.RespBean;
import com.xxxx.yeb.pojo.Role;
import com.xxxx.yeb.service.IAdminService;
import com.xxxx.yeb.service.IMenuService;
import com.xxxx.yeb.service.IRoleService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统配置Controller
 *
 * @author zhoubin
 * @since 1.0.0
 */
@RestController
@RequestMapping("/system/")
public class SystemController {

	@Autowired
	private IMenuService menuService;
	@Autowired
	IAdminService adminService;
	@Autowired
	IRoleService roleService;


	@ApiOperation(value = "根据用户id查询菜单")
	@GetMapping("/menu")
	public List<Menu> getMenusByAdminId(){
		return menuService.getMenusByAdminId();
	}

	@ApiOperation(value = "根据用户姓名查询用户信息")
	@GetMapping("/admin")
	public List<Admin> queryUserByName(String keywords){
		return adminService.queryUserByName(keywords);
	}


	@ApiOperation(value = "根据用户ID删除用户信息")
	@DeleteMapping("/deladmin")
	public RespBean deleteUserByID(Integer id){
		return adminService.deleteUserById(id);
	}

	@ApiOperation(value = "根据用户ID设置启用和禁用")
	@PutMapping("/changeadmin")
	public RespBean enabledChangeById(Integer id){
		return adminService.enabledChangeById(id);
	}

	@ApiOperation(value = "查询当前所有用户角色")
	@GetMapping("/admin/roles")
	public List<Role> queryAllRole(){
		return roleService.queryAllRole();
	}

	@ApiOperation(value = "根据用户id修改当前用户拥有的角色")
	@PutMapping("/admin/role")
	public RespBean updateUserRoleById(Integer adminId,Integer[] rids){
		return roleService.updateUserRoleById(adminId,rids);
	}

	@ApiOperation(value = "查询当前所有角色")
	@GetMapping("/basic/permiss")
	public List<Role> queryAllRoles(){
		return roleService.queryAllRole();
	}

	@ApiOperation(value = "显示角色下的菜单")
	@GetMapping("/basic/permiss/menus")
	public List<Menu> queryAllMenus(){
		return menuService.queryAllMenus();
	}

	@ApiOperation(value = "根据角色id显示当前角色拥有的访问权限")
	@GetMapping("/system/basic/permiss")
	public List<Integer> queryMenuByRoleId(Integer rid){

		return menuService.queryMenuByRoleId(rid);
	}

	@ApiOperation(value = "根据角色id删除当前角色")
	@DeleteMapping("/basic/permiss/role")
	public RespBean deleteRoleById(Integer rid){
		return roleService.deleteRole(rid);
	}

	@ApiOperation(value="添加角色")
    @PostMapping("/basic/permiss/role")
    public RespBean insertRole(@RequestBody Role role){
	    return roleService.insertRole(role.getName(),role.getNameZh());
    }

    @ApiOperation(value = "根据角色ID更新角色权限")
	@PutMapping("/basic/permiss")
	public RespBean updatePermitsByRoleId(Integer rid, Integer[] mids){
		return roleService.updatePermitsByRoleId(rid,mids);
	}
}